<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            border: 0;
            box-sizing: border-box;
        }
        .box {
            position: relative;
            height: 50px;
            line-height: 50px;
        }
        input {
            position: absolute;
            bottom: 5px;
            width: 200px;
            height: 40px;
            line-height: 40px;
            outline: none;
            padding-left: 5px;
            border: 1px solid orange;
        }
        .box .buttons {
            display: inline-block;
            position: absolute;
            bottom: 5px;
            left: 205px;
        }
        .box .buttons button {
            display: block;
            width: 20px;
            height: 20px;
            border: 1px solid gray;
            background-color: skyblue;
        }

    </style>
</head>
<body>
    <div class="box">
        <input type="number" value="0" id="count">
        <div class="buttons">
            <button class="add">+</button>
            <button class="reduce">-</button>
        </div>
    </div>
    <script>
        const input = document.querySelector('input')
        const add = document.querySelector('.add')
        const reduce = document.querySelector('.reduce')
        add.addEventListener('click', function() {
            const value = +input.value
            input.value = `${value + 1}`
        })
        reduce.addEventListener('click', function() {
            const value = +input.value
            if (value <= 0) {
                alert('已经减至最低了')
            }else{
                input.value = `${value - 1}`
            }
            
        })
        input.addEventListener('input', function(){
            const value = +input.value
            if (value <= 0) {
                alert('已经减至最低了')
                input.value = 0
            }
        })
    </script>
</body>
</html>